package cn.sccl.common.model;


import org.springframework.dao.DataRetrievalFailureException;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * 基于Map形式的通用查询参数及查询结果
 * Created by 杨浩宇 on 2016-02-13.
 */
public class QueryData extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public QueryData() {

    }

    public QueryData(Map<String, Object> map) {
        this.putAll(map);
    }

    @Override
    public Object get(Object key) {
        return super.get(key);
    }

    @Override
    public Object put(String key, Object value) {
        if (value instanceof Timestamp) {
            value = toCalendar((Timestamp) value);
        }
        return super.put(key, value);
    }

    protected Calendar toCalendar(Timestamp timestamp) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timestamp.getTime());
        return calendar;
    }


}
